using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

using Cafechess.Chess.Controls;
using Cafechess.Chess.Validation;
using Cafechess.Chess.Parsers;
using Cafechess.Chess.General;
namespace FENImages
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class FENImages : System.Windows.Forms.Form
	{
    private System.Windows.Forms.ColorDialog PickColorsDialog;
    private System.Windows.Forms.Panel panel1;
    private System.Windows.Forms.Panel panel2;
    private System.Windows.Forms.SaveFileDialog SaveFileDialog;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.ComboBox lstCompass;
    private System.Windows.Forms.ComboBox lstPieces;
    private System.Windows.Forms.NumericUpDown imageHeight;
    private System.Windows.Forms.Label label5;
    private ChessSurface savePosition;
    private System.Windows.Forms.ImageList imagePieces;
    private System.Windows.Forms.ComboBox whatLayer;
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.GroupBox groupBox2;
    private System.Windows.Forms.Panel WhiteSquare;
    private System.Windows.Forms.Panel BlackSquare;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label6;
    private System.Windows.Forms.Button btnSave;
    private System.Windows.Forms.Panel BoarderColor;
    private System.Windows.Forms.Label label7;
    private System.Windows.Forms.CheckBox btnFlipped;
    private System.Windows.Forms.NumericUpDown BoarderWidth;
    private System.Windows.Forms.PictureBox pictureBPawn;
    private System.Windows.Forms.PictureBox pictureBKnight;
    private System.Windows.Forms.PictureBox pictureBBishop;
    private System.Windows.Forms.PictureBox pictureBRook;
    private System.Windows.Forms.PictureBox pictureBQueen;
    private System.Windows.Forms.PictureBox pictureBKing;
    private System.Windows.Forms.PictureBox pictureWPawn;
    private System.Windows.Forms.PictureBox pictureWKnight;
    private System.Windows.Forms.PictureBox pictureWBishop;
    private System.Windows.Forms.PictureBox pictureWRook;
    private System.Windows.Forms.PictureBox pictureWQueen;
    private System.Windows.Forms.PictureBox pictureWKing;
    private Cafechess.Chess.Controls.ChessBoard editPosition;
    private System.Windows.Forms.Button btnNew;
    private System.Windows.Forms.Button btnClear;
    private System.ComponentModel.IContainer components;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Panel MoveSquare;
    private System.Windows.Forms.Panel DrawingColor;
    private System.Windows.Forms.Button btnClearLayer;
    private System.Windows.Forms.CheckBox btnSideToMove;
    private System.Windows.Forms.TextBox txtFEN;
    private System.Windows.Forms.Button btnGetFen;
    private System.Windows.Forms.Button btnSetFen;
    private System.Windows.Forms.MainMenu mainMenu1;
    private System.Windows.Forms.MenuItem menuItem1;
    private System.Windows.Forms.MenuItem menuItem2;
    private System.Windows.Forms.MenuItem menuItem3;
    private System.Windows.Forms.MenuItem menuItem4;
    GenericValidation coGeneric;
		public FENImages()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
      savePosition = new ChessSurface(new Rectangle( 0, 0, 100, 100),Color.Transparent);      
      savePosition.ChessImages = imagePieces;
      coGeneric = new GenericValidation(editPosition);
      editPosition.ChessBoardGui.Validation = coGeneric;
      editPosition.ChessBoardGui.IsEditting = true;
      editPosition.ChessBoardGui.IsDrawing = true;
      lstCompass.Items.Add(CompassHeading.None);
      lstCompass.Items.Add(CompassHeading.North);
      lstCompass.Items.Add(CompassHeading.South);
      lstCompass.Items.Add(CompassHeading.East);
      lstCompass.Items.Add(CompassHeading.West);
      lstCompass.Items.Add(CompassHeading.NorthEast);
      lstCompass.Items.Add(CompassHeading.NorthWest);
      lstCompass.Items.Add(CompassHeading.SouthEast);
      lstCompass.Items.Add(CompassHeading.SouthWest);
      lstCompass.Items.Add(CompassHeading.SmallCenter);
      lstCompass.Items.Add(CompassHeading.BigCenter);
      lstCompass.Items.Add(CompassHeading.BiggerCenter);      
      lstCompass.SelectedIndex = 0;
      lstPieces.Items.Add(Pieces.None);
      lstPieces.Items.Add(Pieces.All);
      lstPieces.Items.Add(Pieces.AllPawns);
      lstPieces.Items.Add(Pieces.AllNonPawns);
      lstPieces.Items.Add(Pieces.AllKings);
      lstPieces.Items.Add(Pieces.AllQueens);
      lstPieces.Items.Add(Pieces.AllRooks);
      lstPieces.Items.Add(Pieces.AllBishops);
      lstPieces.Items.Add(Pieces.AllKnights);
      lstPieces.Items.Add(Pieces.AllMinors);
      lstPieces.Items.Add(Pieces.BlackKing);
      lstPieces.Items.Add(Pieces.BlackQueen);
      lstPieces.Items.Add(Pieces.BlackRook);
      lstPieces.Items.Add(Pieces.BlackBishop);
      lstPieces.Items.Add(Pieces.BlackKnight);
      lstPieces.Items.Add(Pieces.BlackPawn);
      lstPieces.Items.Add(Pieces.WhiteKing);
      lstPieces.Items.Add(Pieces.WhiteQueen);
      lstPieces.Items.Add(Pieces.WhiteRook);
      lstPieces.Items.Add(Pieces.WhiteBishop);
      lstPieces.Items.Add(Pieces.WhiteKnight);
      lstPieces.Items.Add(Pieces.WhitePawn);      
      lstPieces.SelectedIndex = 0;
      whatLayer.Items.Add(Layers.DrawTop);
      whatLayer.Items.Add(Layers.DrawMid);
      whatLayer.SelectedIndex = 0;
      editPosition.ChessBoardGui.ActiveLayer = Layers.DrawTop;
      coGlobalSettings = LoadInformation("ConfigValues.xml");      
		}
    Information coGlobalSettings;


		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
      this.components = new System.ComponentModel.Container();
      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FENImages));
      this.PickColorsDialog = new System.Windows.Forms.ColorDialog();
      this.panel1 = new System.Windows.Forms.Panel();
      this.pictureBPawn = new System.Windows.Forms.PictureBox();
      this.pictureBKnight = new System.Windows.Forms.PictureBox();
      this.pictureBBishop = new System.Windows.Forms.PictureBox();
      this.pictureBRook = new System.Windows.Forms.PictureBox();
      this.pictureBQueen = new System.Windows.Forms.PictureBox();
      this.pictureBKing = new System.Windows.Forms.PictureBox();
      this.pictureWPawn = new System.Windows.Forms.PictureBox();
      this.pictureWKnight = new System.Windows.Forms.PictureBox();
      this.pictureWBishop = new System.Windows.Forms.PictureBox();
      this.pictureWRook = new System.Windows.Forms.PictureBox();
      this.pictureWQueen = new System.Windows.Forms.PictureBox();
      this.pictureWKing = new System.Windows.Forms.PictureBox();
      this.editPosition = new Cafechess.Chess.Controls.ChessBoard();
      this.groupBox2 = new System.Windows.Forms.GroupBox();
      this.BoarderWidth = new System.Windows.Forms.NumericUpDown();
      this.btnFlipped = new System.Windows.Forms.CheckBox();
      this.label7 = new System.Windows.Forms.Label();
      this.BoarderColor = new System.Windows.Forms.Panel();
      this.label6 = new System.Windows.Forms.Label();
      this.label2 = new System.Windows.Forms.Label();
      this.WhiteSquare = new System.Windows.Forms.Panel();
      this.BlackSquare = new System.Windows.Forms.Panel();
      this.MoveSquare = new System.Windows.Forms.Panel();
      this.label1 = new System.Windows.Forms.Label();
      this.groupBox1 = new System.Windows.Forms.GroupBox();
      this.btnClearLayer = new System.Windows.Forms.Button();
      this.whatLayer = new System.Windows.Forms.ComboBox();
      this.DrawingColor = new System.Windows.Forms.Panel();
      this.btnSideToMove = new System.Windows.Forms.CheckBox();
      this.panel2 = new System.Windows.Forms.Panel();
      this.btnSetFen = new System.Windows.Forms.Button();
      this.btnGetFen = new System.Windows.Forms.Button();
      this.txtFEN = new System.Windows.Forms.TextBox();
      this.btnClear = new System.Windows.Forms.Button();
      this.btnNew = new System.Windows.Forms.Button();
      this.btnSave = new System.Windows.Forms.Button();
      this.label5 = new System.Windows.Forms.Label();
      this.imageHeight = new System.Windows.Forms.NumericUpDown();
      this.label3 = new System.Windows.Forms.Label();
      this.lstCompass = new System.Windows.Forms.ComboBox();
      this.lstPieces = new System.Windows.Forms.ComboBox();
      this.SaveFileDialog = new System.Windows.Forms.SaveFileDialog();
      this.imagePieces = new System.Windows.Forms.ImageList(this.components);
      this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
      this.menuItem1 = new System.Windows.Forms.MenuItem();
      this.menuItem2 = new System.Windows.Forms.MenuItem();
      this.menuItem3 = new System.Windows.Forms.MenuItem();
      this.menuItem4 = new System.Windows.Forms.MenuItem();
      this.panel1.SuspendLayout();
      ((System.ComponentModel.ISupportInitialize)(this.pictureBPawn)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureBKnight)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureBBishop)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureBRook)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureBQueen)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureBKing)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureWPawn)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureWKnight)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureWBishop)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureWRook)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureWQueen)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureWKing)).BeginInit();
      this.groupBox2.SuspendLayout();
      ((System.ComponentModel.ISupportInitialize)(this.BoarderWidth)).BeginInit();
      this.groupBox1.SuspendLayout();
      this.panel2.SuspendLayout();
      ((System.ComponentModel.ISupportInitialize)(this.imageHeight)).BeginInit();
      this.SuspendLayout();
      // 
      // panel1
      // 
      this.panel1.Controls.Add(this.pictureBPawn);
      this.panel1.Controls.Add(this.pictureBKnight);
      this.panel1.Controls.Add(this.pictureBBishop);
      this.panel1.Controls.Add(this.pictureBRook);
      this.panel1.Controls.Add(this.pictureBQueen);
      this.panel1.Controls.Add(this.pictureBKing);
      this.panel1.Controls.Add(this.pictureWPawn);
      this.panel1.Controls.Add(this.pictureWKnight);
      this.panel1.Controls.Add(this.pictureWBishop);
      this.panel1.Controls.Add(this.pictureWRook);
      this.panel1.Controls.Add(this.pictureWQueen);
      this.panel1.Controls.Add(this.pictureWKing);
      this.panel1.Controls.Add(this.editPosition);
      this.panel1.Controls.Add(this.groupBox2);
      this.panel1.Controls.Add(this.groupBox1);
      this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
      this.panel1.Location = new System.Drawing.Point(0, 0);
      this.panel1.Name = "panel1";
      this.panel1.Size = new System.Drawing.Size(633, 542);
      this.panel1.TabIndex = 0;
      // 
      // pictureBPawn
      // 
      this.pictureBPawn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
      this.pictureBPawn.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.pictureBPawn.Image = ((System.Drawing.Image)(resources.GetObject("pictureBPawn.Image")));
      this.pictureBPawn.ImeMode = System.Windows.Forms.ImeMode.NoControl;
      this.pictureBPawn.Location = new System.Drawing.Point(473, 184);
      this.pictureBPawn.Name = "pictureBPawn";
      this.pictureBPawn.Size = new System.Drawing.Size(32, 32);
      this.pictureBPawn.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
      this.pictureBPawn.TabIndex = 70;
      this.pictureBPawn.TabStop = false;
      this.pictureBPawn.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBPawn_MouseDown);
      // 
      // pictureBKnight
      // 
      this.pictureBKnight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
      this.pictureBKnight.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.pictureBKnight.Image = ((System.Drawing.Image)(resources.GetObject("pictureBKnight.Image")));
      this.pictureBKnight.ImeMode = System.Windows.Forms.ImeMode.NoControl;
      this.pictureBKnight.Location = new System.Drawing.Point(473, 152);
      this.pictureBKnight.Name = "pictureBKnight";
      this.pictureBKnight.Size = new System.Drawing.Size(32, 32);
      this.pictureBKnight.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
      this.pictureBKnight.TabIndex = 69;
      this.pictureBKnight.TabStop = false;
      this.pictureBKnight.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBKnight_MouseDown);
      // 
      // pictureBBishop
      // 
      this.pictureBBishop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
      this.pictureBBishop.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.pictureBBishop.Image = ((System.Drawing.Image)(resources.GetObject("pictureBBishop.Image")));
      this.pictureBBishop.ImeMode = System.Windows.Forms.ImeMode.NoControl;
      this.pictureBBishop.Location = new System.Drawing.Point(473, 120);
      this.pictureBBishop.Name = "pictureBBishop";
      this.pictureBBishop.Size = new System.Drawing.Size(32, 32);
      this.pictureBBishop.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
      this.pictureBBishop.TabIndex = 68;
      this.pictureBBishop.TabStop = false;
      this.pictureBBishop.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBBishop_MouseDown);
      // 
      // pictureBRook
      // 
      this.pictureBRook.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
      this.pictureBRook.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.pictureBRook.Image = ((System.Drawing.Image)(resources.GetObject("pictureBRook.Image")));
      this.pictureBRook.ImeMode = System.Windows.Forms.ImeMode.NoControl;
      this.pictureBRook.Location = new System.Drawing.Point(473, 88);
      this.pictureBRook.Name = "pictureBRook";
      this.pictureBRook.Size = new System.Drawing.Size(32, 32);
      this.pictureBRook.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
      this.pictureBRook.TabIndex = 67;
      this.pictureBRook.TabStop = false;
      this.pictureBRook.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBRook_MouseDown);
      // 
      // pictureBQueen
      // 
      this.pictureBQueen.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
      this.pictureBQueen.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.pictureBQueen.Image = ((System.Drawing.Image)(resources.GetObject("pictureBQueen.Image")));
      this.pictureBQueen.ImeMode = System.Windows.Forms.ImeMode.NoControl;
      this.pictureBQueen.Location = new System.Drawing.Point(473, 56);
      this.pictureBQueen.Name = "pictureBQueen";
      this.pictureBQueen.Size = new System.Drawing.Size(32, 32);
      this.pictureBQueen.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
      this.pictureBQueen.TabIndex = 66;
      this.pictureBQueen.TabStop = false;
      this.pictureBQueen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBQueen_MouseDown);
      // 
      // pictureBKing
      // 
      this.pictureBKing.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
      this.pictureBKing.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.pictureBKing.Image = ((System.Drawing.Image)(resources.GetObject("pictureBKing.Image")));
      this.pictureBKing.ImeMode = System.Windows.Forms.ImeMode.NoControl;
      this.pictureBKing.Location = new System.Drawing.Point(473, 24);
      this.pictureBKing.Name = "pictureBKing";
      this.pictureBKing.Size = new System.Drawing.Size(32, 32);
      this.pictureBKing.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
      this.pictureBKing.TabIndex = 65;
      this.pictureBKing.TabStop = false;
      this.pictureBKing.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBKing_MouseDown);
      // 
      // pictureWPawn
      // 
      this.pictureWPawn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
      this.pictureWPawn.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.pictureWPawn.Image = ((System.Drawing.Image)(resources.GetObject("pictureWPawn.Image")));
      this.pictureWPawn.ImeMode = System.Windows.Forms.ImeMode.NoControl;
      this.pictureWPawn.Location = new System.Drawing.Point(433, 184);
      this.pictureWPawn.Name = "pictureWPawn";
      this.pictureWPawn.Size = new System.Drawing.Size(32, 32);
      this.pictureWPawn.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
      this.pictureWPawn.TabIndex = 64;
      this.pictureWPawn.TabStop = false;
      this.pictureWPawn.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureWPawn_MouseDown);
      // 
      // pictureWKnight
      // 
      this.pictureWKnight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
      this.pictureWKnight.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.pictureWKnight.Image = ((System.Drawing.Image)(resources.GetObject("pictureWKnight.Image")));
      this.pictureWKnight.ImeMode = System.Windows.Forms.ImeMode.NoControl;
      this.pictureWKnight.Location = new System.Drawing.Point(433, 152);
      this.pictureWKnight.Name = "pictureWKnight";
      this.pictureWKnight.Size = new System.Drawing.Size(32, 32);
      this.pictureWKnight.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
      this.pictureWKnight.TabIndex = 63;
      this.pictureWKnight.TabStop = false;
      this.pictureWKnight.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureWKnight_MouseDown);
      // 
      // pictureWBishop
      // 
      this.pictureWBishop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
      this.pictureWBishop.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.pictureWBishop.Image = ((System.Drawing.Image)(resources.GetObject("pictureWBishop.Image")));
      this.pictureWBishop.ImeMode = System.Windows.Forms.ImeMode.NoControl;
      this.pictureWBishop.Location = new System.Drawing.Point(433, 120);
      this.pictureWBishop.Name = "pictureWBishop";
      this.pictureWBishop.Size = new System.Drawing.Size(32, 32);
      this.pictureWBishop.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
      this.pictureWBishop.TabIndex = 62;
      this.pictureWBishop.TabStop = false;
      this.pictureWBishop.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureWBishop_MouseDown);
      // 
      // pictureWRook
      // 
      this.pictureWRook.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
      this.pictureWRook.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.pictureWRook.Image = ((System.Drawing.Image)(resources.GetObject("pictureWRook.Image")));
      this.pictureWRook.ImeMode = System.Windows.Forms.ImeMode.NoControl;
      this.pictureWRook.Location = new System.Drawing.Point(433, 88);
      this.pictureWRook.Name = "pictureWRook";
      this.pictureWRook.Size = new System.Drawing.Size(32, 32);
      this.pictureWRook.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
      this.pictureWRook.TabIndex = 61;
      this.pictureWRook.TabStop = false;
      this.pictureWRook.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureWRook_MouseDown);
      // 
      // pictureWQueen
      // 
      this.pictureWQueen.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
      this.pictureWQueen.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.pictureWQueen.Image = ((System.Drawing.Image)(resources.GetObject("pictureWQueen.Image")));
      this.pictureWQueen.ImeMode = System.Windows.Forms.ImeMode.NoControl;
      this.pictureWQueen.Location = new System.Drawing.Point(433, 56);
      this.pictureWQueen.Name = "pictureWQueen";
      this.pictureWQueen.Size = new System.Drawing.Size(32, 32);
      this.pictureWQueen.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
      this.pictureWQueen.TabIndex = 60;
      this.pictureWQueen.TabStop = false;
      this.pictureWQueen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureWQueen_MouseDown);
      // 
      // pictureWKing
      // 
      this.pictureWKing.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
      this.pictureWKing.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.pictureWKing.Image = ((System.Drawing.Image)(resources.GetObject("pictureWKing.Image")));
      this.pictureWKing.ImeMode = System.Windows.Forms.ImeMode.NoControl;
      this.pictureWKing.Location = new System.Drawing.Point(433, 24);
      this.pictureWKing.Name = "pictureWKing";
      this.pictureWKing.Size = new System.Drawing.Size(32, 32);
      this.pictureWKing.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
      this.pictureWKing.TabIndex = 59;
      this.pictureWKing.TabStop = false;
      this.pictureWKing.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureWKing_MouseDown);
      // 
      // editPosition
      // 
      this.editPosition.AllowDrop = true;
      this.editPosition.EnableAltKeys = true;
      this.editPosition.Location = new System.Drawing.Point(16, 16);
      this.editPosition.Name = "editPosition";
      this.editPosition.Size = new System.Drawing.Size(400, 400);
      this.editPosition.TabIndex = 58;
      // 
      // groupBox2
      // 
      this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
      this.groupBox2.Controls.Add(this.BoarderWidth);
      this.groupBox2.Controls.Add(this.btnFlipped);
      this.groupBox2.Controls.Add(this.label7);
      this.groupBox2.Controls.Add(this.BoarderColor);
      this.groupBox2.Controls.Add(this.label6);
      this.groupBox2.Controls.Add(this.label2);
      this.groupBox2.Controls.Add(this.WhiteSquare);
      this.groupBox2.Controls.Add(this.BlackSquare);
      this.groupBox2.Controls.Add(this.MoveSquare);
      this.groupBox2.Controls.Add(this.label1);
      this.groupBox2.Location = new System.Drawing.Point(513, 104);
      this.groupBox2.Name = "groupBox2";
      this.groupBox2.Size = new System.Drawing.Size(104, 216);
      this.groupBox2.TabIndex = 57;
      this.groupBox2.TabStop = false;
      this.groupBox2.Text = "Board";
      // 
      // BoarderWidth
      // 
      this.BoarderWidth.Location = new System.Drawing.Point(8, 152);
      this.BoarderWidth.Maximum = new decimal(new int[] {
            20,
            0,
            0,
            0});
      this.BoarderWidth.Name = "BoarderWidth";
      this.BoarderWidth.Size = new System.Drawing.Size(72, 20);
      this.BoarderWidth.TabIndex = 8;
      this.BoarderWidth.Value = new decimal(new int[] {
            15,
            0,
            0,
            0});
      this.BoarderWidth.ValueChanged += new System.EventHandler(this.BoarderWidth_ValueChanged);
      // 
      // btnFlipped
      // 
      this.btnFlipped.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
      this.btnFlipped.Location = new System.Drawing.Point(8, 176);
      this.btnFlipped.Name = "btnFlipped";
      this.btnFlipped.Size = new System.Drawing.Size(80, 24);
      this.btnFlipped.TabIndex = 7;
      this.btnFlipped.Text = "Flipped";
      this.btnFlipped.CheckedChanged += new System.EventHandler(this.btnFlipped_CheckedChanged);
      // 
      // label7
      // 
      this.label7.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
      this.label7.Location = new System.Drawing.Point(32, 88);
      this.label7.Name = "label7";
      this.label7.Size = new System.Drawing.Size(56, 23);
      this.label7.TabIndex = 6;
      this.label7.Text = "Boarder";
      this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
      // 
      // BoarderColor
      // 
      this.BoarderColor.BackColor = System.Drawing.Color.Beige;
      this.BoarderColor.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.BoarderColor.Location = new System.Drawing.Point(8, 88);
      this.BoarderColor.Name = "BoarderColor";
      this.BoarderColor.Size = new System.Drawing.Size(24, 24);
      this.BoarderColor.TabIndex = 5;
      this.BoarderColor.MouseDown += new System.Windows.Forms.MouseEventHandler(this.BoarderColor_MouseDown);
      // 
      // label6
      // 
      this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
      this.label6.Location = new System.Drawing.Point(32, 56);
      this.label6.Name = "label6";
      this.label6.Size = new System.Drawing.Size(40, 23);
      this.label6.TabIndex = 4;
      this.label6.Text = "Black";
      this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
      // 
      // label2
      // 
      this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
      this.label2.Location = new System.Drawing.Point(32, 24);
      this.label2.Name = "label2";
      this.label2.Size = new System.Drawing.Size(40, 23);
      this.label2.TabIndex = 3;
      this.label2.Text = "White";
      this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
      // 
      // WhiteSquare
      // 
      this.WhiteSquare.BackColor = System.Drawing.Color.LightGoldenrodYellow;
      this.WhiteSquare.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.WhiteSquare.Location = new System.Drawing.Point(8, 24);
      this.WhiteSquare.Name = "WhiteSquare";
      this.WhiteSquare.Size = new System.Drawing.Size(24, 24);
      this.WhiteSquare.TabIndex = 1;
      this.WhiteSquare.MouseDown += new System.Windows.Forms.MouseEventHandler(this.WhiteSquare_MouseDown);
      // 
      // BlackSquare
      // 
      this.BlackSquare.BackColor = System.Drawing.Color.PaleGoldenrod;
      this.BlackSquare.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.BlackSquare.Location = new System.Drawing.Point(8, 56);
      this.BlackSquare.Name = "BlackSquare";
      this.BlackSquare.Size = new System.Drawing.Size(24, 24);
      this.BlackSquare.TabIndex = 2;
      this.BlackSquare.MouseDown += new System.Windows.Forms.MouseEventHandler(this.BlackSquare_MouseDown);
      // 
      // MoveSquare
      // 
      this.MoveSquare.BackColor = System.Drawing.Color.LightSteelBlue;
      this.MoveSquare.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.MoveSquare.Location = new System.Drawing.Point(8, 120);
      this.MoveSquare.Name = "MoveSquare";
      this.MoveSquare.Size = new System.Drawing.Size(24, 24);
      this.MoveSquare.TabIndex = 9;
      this.MoveSquare.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MoveSquare_MouseDown);
      // 
      // label1
      // 
      this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
      this.label1.Location = new System.Drawing.Point(32, 120);
      this.label1.Name = "label1";
      this.label1.Size = new System.Drawing.Size(40, 23);
      this.label1.TabIndex = 10;
      this.label1.Text = "Moves";
      this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
      // 
      // groupBox1
      // 
      this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
      this.groupBox1.Controls.Add(this.btnClearLayer);
      this.groupBox1.Controls.Add(this.whatLayer);
      this.groupBox1.Controls.Add(this.DrawingColor);
      this.groupBox1.Location = new System.Drawing.Point(513, 16);
      this.groupBox1.Name = "groupBox1";
      this.groupBox1.Size = new System.Drawing.Size(104, 80);
      this.groupBox1.TabIndex = 56;
      this.groupBox1.TabStop = false;
      this.groupBox1.Text = "Drawing Colors";
      // 
      // btnClearLayer
      // 
      this.btnClearLayer.Location = new System.Drawing.Point(56, 16);
      this.btnClearLayer.Name = "btnClearLayer";
      this.btnClearLayer.Size = new System.Drawing.Size(40, 23);
      this.btnClearLayer.TabIndex = 55;
      this.btnClearLayer.Text = "Clear";
      this.btnClearLayer.Click += new System.EventHandler(this.btnClearLayer_Click);
      // 
      // whatLayer
      // 
      this.whatLayer.Location = new System.Drawing.Point(5, 48);
      this.whatLayer.Name = "whatLayer";
      this.whatLayer.Size = new System.Drawing.Size(96, 21);
      this.whatLayer.TabIndex = 54;
      this.whatLayer.SelectedIndexChanged += new System.EventHandler(this.whatLayer_SelectedIndexChanged);
      // 
      // DrawingColor
      // 
      this.DrawingColor.BackColor = System.Drawing.Color.PaleGreen;
      this.DrawingColor.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.DrawingColor.Location = new System.Drawing.Point(6, 24);
      this.DrawingColor.Name = "DrawingColor";
      this.DrawingColor.Size = new System.Drawing.Size(24, 24);
      this.DrawingColor.TabIndex = 0;
      this.DrawingColor.Click += new System.EventHandler(this.panel3_Click);
      // 
      // btnSideToMove
      // 
      this.btnSideToMove.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
      this.btnSideToMove.Checked = true;
      this.btnSideToMove.CheckState = System.Windows.Forms.CheckState.Checked;
      this.btnSideToMove.Location = new System.Drawing.Point(230, 40);
      this.btnSideToMove.Name = "btnSideToMove";
      this.btnSideToMove.Size = new System.Drawing.Size(96, 32);
      this.btnSideToMove.TabIndex = 72;
      this.btnSideToMove.Text = "Whites move";
      this.btnSideToMove.CheckedChanged += new System.EventHandler(this.btnSideToMove_CheckedChanged);
      // 
      // panel2
      // 
      this.panel2.Controls.Add(this.btnSetFen);
      this.panel2.Controls.Add(this.btnGetFen);
      this.panel2.Controls.Add(this.txtFEN);
      this.panel2.Controls.Add(this.btnClear);
      this.panel2.Controls.Add(this.btnNew);
      this.panel2.Controls.Add(this.btnSave);
      this.panel2.Controls.Add(this.label5);
      this.panel2.Controls.Add(this.imageHeight);
      this.panel2.Controls.Add(this.label3);
      this.panel2.Controls.Add(this.lstCompass);
      this.panel2.Controls.Add(this.lstPieces);
      this.panel2.Controls.Add(this.btnSideToMove);
      this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
      this.panel2.Location = new System.Drawing.Point(0, 438);
      this.panel2.Name = "panel2";
      this.panel2.Size = new System.Drawing.Size(633, 104);
      this.panel2.TabIndex = 1;
      // 
      // btnSetFen
      // 
      this.btnSetFen.Location = new System.Drawing.Point(569, 69);
      this.btnSetFen.Name = "btnSetFen";
      this.btnSetFen.Size = new System.Drawing.Size(56, 23);
      this.btnSetFen.TabIndex = 59;
      this.btnSetFen.Text = "Set FEN";
      this.btnSetFen.Click += new System.EventHandler(this.btnSetFen_Click);
      // 
      // btnGetFen
      // 
      this.btnGetFen.Location = new System.Drawing.Point(505, 69);
      this.btnGetFen.Name = "btnGetFen";
      this.btnGetFen.Size = new System.Drawing.Size(56, 23);
      this.btnGetFen.TabIndex = 58;
      this.btnGetFen.Text = "Get FEN";
      this.btnGetFen.Click += new System.EventHandler(this.btnGetFen_Click);
      // 
      // txtFEN
      // 
      this.txtFEN.Location = new System.Drawing.Point(16, 69);
      this.txtFEN.Name = "txtFEN";
      this.txtFEN.Size = new System.Drawing.Size(481, 20);
      this.txtFEN.TabIndex = 57;
      // 
      // btnClear
      // 
      this.btnClear.Location = new System.Drawing.Point(441, 13);
      this.btnClear.Name = "btnClear";
      this.btnClear.Size = new System.Drawing.Size(48, 23);
      this.btnClear.TabIndex = 56;
      this.btnClear.Text = "Clear";
      this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
      // 
      // btnNew
      // 
      this.btnNew.Location = new System.Drawing.Point(495, 13);
      this.btnNew.Name = "btnNew";
      this.btnNew.Size = new System.Drawing.Size(48, 23);
      this.btnNew.TabIndex = 55;
      this.btnNew.Text = "New";
      this.btnNew.Click += new System.EventHandler(this.btnNew_Click);
      // 
      // btnSave
      // 
      this.btnSave.Location = new System.Drawing.Point(548, 13);
      this.btnSave.Name = "btnSave";
      this.btnSave.Size = new System.Drawing.Size(48, 23);
      this.btnSave.TabIndex = 54;
      this.btnSave.Text = "Save";
      this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
      // 
      // label5
      // 
      this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
      this.label5.Location = new System.Drawing.Point(14, 45);
      this.label5.Name = "label5";
      this.label5.Size = new System.Drawing.Size(72, 23);
      this.label5.TabIndex = 53;
      this.label5.Text = "Image Size:";
      this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
      // 
      // imageHeight
      // 
      this.imageHeight.Increment = new decimal(new int[] {
            5,
            0,
            0,
            0});
      this.imageHeight.Location = new System.Drawing.Point(102, 45);
      this.imageHeight.Maximum = new decimal(new int[] {
            800,
            0,
            0,
            0});
      this.imageHeight.Minimum = new decimal(new int[] {
            100,
            0,
            0,
            0});
      this.imageHeight.Name = "imageHeight";
      this.imageHeight.Size = new System.Drawing.Size(64, 20);
      this.imageHeight.TabIndex = 50;
      this.imageHeight.Value = new decimal(new int[] {
            250,
            0,
            0,
            0});
      this.imageHeight.ValueChanged += new System.EventHandler(this.imageHeight_ValueChanged);
      // 
      // label3
      // 
      this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
      this.label3.Location = new System.Drawing.Point(14, 13);
      this.label3.Name = "label3";
      this.label3.Size = new System.Drawing.Size(72, 23);
      this.label3.TabIndex = 48;
      this.label3.Text = "Hide Pieces:";
      this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
      // 
      // lstCompass
      // 
      this.lstCompass.Location = new System.Drawing.Point(214, 13);
      this.lstCompass.Name = "lstCompass";
      this.lstCompass.Size = new System.Drawing.Size(112, 21);
      this.lstCompass.TabIndex = 47;
      this.lstCompass.SelectedIndexChanged += new System.EventHandler(this.lstCompass_SelectedIndexChanged);
      // 
      // lstPieces
      // 
      this.lstPieces.Location = new System.Drawing.Point(102, 13);
      this.lstPieces.Name = "lstPieces";
      this.lstPieces.Size = new System.Drawing.Size(112, 21);
      this.lstPieces.TabIndex = 46;
      this.lstPieces.SelectedIndexChanged += new System.EventHandler(this.lstPieces_SelectedIndexChanged);
      // 
      // SaveFileDialog
      // 
      this.SaveFileDialog.DefaultExt = "bmp";
      this.SaveFileDialog.Filter = "Bitmap files|*.bmp";
      // 
      // imagePieces
      // 
      this.imagePieces.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imagePieces.ImageStream")));
      this.imagePieces.TransparentColor = System.Drawing.Color.Transparent;
      this.imagePieces.Images.SetKeyName(0, "");
      this.imagePieces.Images.SetKeyName(1, "");
      this.imagePieces.Images.SetKeyName(2, "");
      this.imagePieces.Images.SetKeyName(3, "");
      this.imagePieces.Images.SetKeyName(4, "");
      this.imagePieces.Images.SetKeyName(5, "");
      this.imagePieces.Images.SetKeyName(6, "");
      this.imagePieces.Images.SetKeyName(7, "");
      this.imagePieces.Images.SetKeyName(8, "");
      this.imagePieces.Images.SetKeyName(9, "");
      this.imagePieces.Images.SetKeyName(10, "");
      this.imagePieces.Images.SetKeyName(11, "");
      // 
      // mainMenu1
      // 
      this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem1});
      // 
      // menuItem1
      // 
      this.menuItem1.Index = 0;
      this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem2,
            this.menuItem3,
            this.menuItem4});
      this.menuItem1.Text = "Options";
      this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
      // 
      // menuItem2
      // 
      this.menuItem2.Index = 0;
      this.menuItem2.Text = "Highlight One Piece";
      // 
      // menuItem3
      // 
      this.menuItem3.Index = 1;
      this.menuItem3.Text = "Pin Highlight To Current ";
      // 
      // menuItem4
      // 
      this.menuItem4.Index = 2;
      this.menuItem4.Text = "About";
      this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
      // 
      // FENImages
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(633, 542);
      this.Controls.Add(this.panel2);
      this.Controls.Add(this.panel1);
      this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
      this.KeyPreview = true;
      this.MaximizeBox = false;
      this.Menu = this.mainMenu1;
      this.MinimizeBox = false;
      this.Name = "FENImages";
      this.Text = "Cafechess Image Editor";
      this.Load += new System.EventHandler(this.FENImages_Load);
      this.Closing += new System.ComponentModel.CancelEventHandler(this.FENImages_Closing);
      this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.FENImages_KeyPress);
      this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.FENImages_KeyUp);
      this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FENImages_KeyDown);
      this.panel1.ResumeLayout(false);
      ((System.ComponentModel.ISupportInitialize)(this.pictureBPawn)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureBKnight)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureBBishop)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureBRook)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureBQueen)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureBKing)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureWPawn)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureWKnight)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureWBishop)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureWRook)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureWQueen)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureWKing)).EndInit();
      this.groupBox2.ResumeLayout(false);
      ((System.ComponentModel.ISupportInitialize)(this.BoarderWidth)).EndInit();
      this.groupBox1.ResumeLayout(false);
      this.panel2.ResumeLayout(false);
      this.panel2.PerformLayout();
      ((System.ComponentModel.ISupportInitialize)(this.imageHeight)).EndInit();
      this.ResumeLayout(false);

    }
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new FENImages());
		}

    Information LoadInformation(string filename)
    {
      Information aInformation;
      if(File.Exists(filename))
      {
        XmlSerializer serializer = new XmlSerializer(typeof(Information));
        StreamReader reader = new StreamReader(filename);
        aInformation = (Information)serializer.Deserialize(reader);
        reader.Close();      
        MoveSquare.BackColor = ColorTranslator.FromHtml(aInformation.Attacks.color);
        BlackSquare.BackColor = ColorTranslator.FromHtml(aInformation.BlackSquare.color);
        WhiteSquare.BackColor = ColorTranslator.FromHtml(aInformation.WhiteSquare.color);
        BoarderColor.BackColor = ColorTranslator.FromHtml(aInformation.Boarder.color);
        BoarderWidth.Value = Convert.ToDecimal( aInformation.Boarder.width);
        DrawingColor.BackColor = ColorTranslator.FromHtml(aInformation.Drawing.color);
        imageHeight.Value = Convert.ToDecimal(aInformation.ImageSize.size);        
      }
      else
      {
        aInformation = new Information();
        aInformation.Attacks = new InformationAttacks();
        aInformation.Attacks.color = ColorTranslator.ToHtml(editPosition.ChessBoardGui.AttacksColor);
        aInformation.BlackSquare = new InformationBlackSquare();
        aInformation.BlackSquare.color = ColorTranslator.ToHtml(editPosition.ChessBoardGui.BlackColor);
        aInformation.WhiteSquare = new InformationWhiteSquare();  
        aInformation.WhiteSquare.color = ColorTranslator.ToHtml(editPosition.ChessBoardGui.WhiteColor);
        aInformation.Boarder = new InformationBoarder();
        aInformation.Boarder.color = ColorTranslator.ToHtml(editPosition.ChessBoardGui.BoarderColor);
        aInformation.Boarder.width = editPosition.ChessBoardGui.BoarderWidth.ToString();
        aInformation.Drawing = new InformationDrawing();
        aInformation.Drawing.color = ColorTranslator.ToHtml(DrawingColor.BackColor);
        aInformation.ImageSize = new InformationImageSize();
        aInformation.ImageSize.size = imageHeight.Value.ToString();
      }

      editPosition.ChessBoardGui.ColorSquares(WhiteSquare.BackColor,BlackSquare.BackColor);
      savePosition.ColorSquares(WhiteSquare.BackColor,BlackSquare.BackColor);
      editPosition.ChessBoardGui.DefaultDrawingColor = DrawingColor.BackColor;
      savePosition.DefaultDrawingColor = DrawingColor.BackColor;
      editPosition.ChessBoardGui.ColorBoarder(BoarderColor.BackColor);
      savePosition.ColorBoarder(BoarderColor.BackColor);     
      return aInformation;
    }
    void SaveInformation(Information aInformation, string filename)
    {
      XmlSerializer serializer = new XmlSerializer(typeof(Information));

      if(File.Exists(filename))
      {
        File.Delete(filename);
      }

      StreamWriter writer = new StreamWriter(filename);
      aInformation.Attacks.color = ColorTranslator.ToHtml(editPosition.ChessBoardGui.AttacksColor);
      aInformation.BlackSquare.color = ColorTranslator.ToHtml(editPosition.ChessBoardGui.BlackColor);
      aInformation.WhiteSquare.color = ColorTranslator.ToHtml(editPosition.ChessBoardGui.WhiteColor);
      aInformation.Boarder.color = ColorTranslator.ToHtml(editPosition.ChessBoardGui.BoarderColor);
      aInformation.Boarder.width = editPosition.ChessBoardGui.BoarderWidth.ToString();
      aInformation.Drawing.color = ColorTranslator.ToHtml(DrawingColor.BackColor);
      aInformation.ImageSize.size = imageHeight.Value.ToString();
      serializer.Serialize(writer,aInformation);
      writer.Close();
    }

    private void panel3_Click(object sender, System.EventArgs e)
    {
      DrawingColor.BackColor = GetColor(BlackSquare.BackColor);
      editPosition.ChessBoardGui.ActiveLayer = (Layers) whatLayer.SelectedItem;
      savePosition.ActiveLayer = (Layers) whatLayer.SelectedItem;
      editPosition.ChessBoardGui.DefaultDrawingColor = DrawingColor.BackColor;
      savePosition.DefaultDrawingColor = DrawingColor.BackColor;
    }
    private void whatLayer_SelectedIndexChanged(object sender, System.EventArgs e)
    {
      if( whatLayer.SelectedItem != null )
      {
        editPosition.ChessBoardGui.ActiveLayer = (Layers) whatLayer.SelectedItem;
        savePosition.ActiveLayer = (Layers) whatLayer.SelectedItem;
        editPosition.ChessBoardGui.DefaultDrawingColor = DrawingColor.BackColor;
        savePosition.DefaultDrawingColor = DrawingColor.BackColor;

      }
    
    }

    private void lstPieces_SelectedIndexChanged(object sender, System.EventArgs e)
    {
      if( lstPieces.SelectedItem != null && lstCompass.SelectedItem != null )
      {
          editPosition.ChessBoardGui.Hide((Pieces)lstPieces.SelectedItem,
          (CompassHeading)lstCompass.SelectedItem);
        savePosition.Hide((Pieces)lstPieces.SelectedItem, 
          (CompassHeading)lstCompass.SelectedItem);
      }

    }

    private void lstCompass_SelectedIndexChanged(object sender, System.EventArgs e)
    {
      if( lstPieces.SelectedItem != null && lstCompass.SelectedItem != null )
      {
        editPosition.ChessBoardGui.Hide((Pieces)lstPieces.SelectedItem, 
          (CompassHeading)lstCompass.SelectedItem);
        savePosition.Hide((Pieces)lstPieces.SelectedItem, 
          (CompassHeading)lstCompass.SelectedItem);

      }
    }

    private void WhiteSquare_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      WhiteSquare.BackColor = GetColor(WhiteSquare.BackColor);
      editPosition.ChessBoardGui.ColorSquares(WhiteSquare.BackColor,BlackSquare.BackColor);
      savePosition.ColorSquares(WhiteSquare.BackColor,BlackSquare.BackColor);
      editPosition.Invalidate();
    }
    private void BlackSquare_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      BlackSquare.BackColor = GetColor(BlackSquare.BackColor);
      editPosition.ChessBoardGui.ColorSquares(WhiteSquare.BackColor,BlackSquare.BackColor);
      savePosition.ColorSquares(WhiteSquare.BackColor,BlackSquare.BackColor);
      editPosition.Invalidate();
    }

    Color GetColor(Color current)
    {     
      PickColorsDialog.Color = current;
      if( PickColorsDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK )
      {
        current = PickColorsDialog.Color;
        editPosition.ChessBoardGui.DefaultDrawingColor = DrawingColor.BackColor;
      }
      return current;
    }

    private void btnSave_Click(object sender, System.EventArgs e)
    {
      if(SaveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK )
      {        
        TransferToSavePosition();
        savePosition.Drawing.Save(SaveFileDialog.FileName);
      }    
    }

    void TransferToSavePosition()
    {
      savePosition.Square = new Rectangle(0,0,Convert.ToInt32(imageHeight.Value), Convert.ToInt32(imageHeight.Value));
      savePosition.ColorSquares(WhiteSquare.BackColor,BlackSquare.BackColor);
      savePosition.FenNotation = editPosition.ChessBoardGui.ImageFenNotation;
      editPosition.ChessBoardGui.ActiveLayer = Layers.DrawTop;
      savePosition.TopDrawingLayer.FromString(editPosition.ChessBoardGui.LayerNotation);
      editPosition.ChessBoardGui.ActiveLayer = Layers.DrawMid;
      savePosition.MidDrawingLayer.FromString(editPosition.ChessBoardGui.LayerNotation);
      savePosition.Hide((Pieces)lstPieces.SelectedItem, (CompassHeading)lstCompass.SelectedItem);
      savePosition.BoarderWidth = Convert.ToInt32(BoarderWidth.Value);
      savePosition.AttacksColor = MoveSquare.BackColor;
      savePosition.AlternateColorSquares(editPosition.ChessBoardGui.LastHighlights,savePosition.AttacksColor);
      savePosition.Render();
    }

    private void BoarderColor_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      BoarderColor.BackColor =  GetColor(BoarderColor.BackColor);
      editPosition.ChessBoardGui.ColorBoarder(BoarderColor.BackColor);
      savePosition.ColorBoarder(BoarderColor.BackColor);
      editPosition.Invalidate();
    }

    private void btnFlipped_CheckedChanged(object sender, System.EventArgs e)
    {
      editPosition.ChessBoardGui.IsFlipped = btnFlipped.Checked;    
    }

    private void btnBoarder_CheckedChanged(object sender, System.EventArgs e)
    {
      editPosition.ChessBoardGui.IsFlipped = btnFlipped.Checked;    
    }

    private void numericUpDown1_ValueChanged(object sender, System.EventArgs e)
    {
      
    
    }

    private void BoarderWidth_ValueChanged(object sender, System.EventArgs e)
    {
      editPosition.ChessBoardGui.BoarderWidth = Convert.ToInt32(BoarderWidth.Value);
      savePosition.BoarderWidth = Convert.ToInt32(BoarderWidth.Value);
      editPosition.Invalidate();
    }
    private void pictureWKing_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      DoDragDrop("whiteking",DragDropEffects.Copy);
    }

    private void pictureWQueen_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      DoDragDrop("whitequeen",DragDropEffects.Copy);   
    }

    private void pictureWRook_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      DoDragDrop("whiterook",DragDropEffects.Copy);   
    }

    private void pictureWBishop_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      DoDragDrop("whitebishop",DragDropEffects.Copy);
    }

    private void pictureWKnight_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      DoDragDrop("whiteknight",DragDropEffects.Copy);
    }

    private void pictureWPawn_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      DoDragDrop("whitepawn",DragDropEffects.Copy);  
    }

    private void pictureBKing_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      DoDragDrop("blackking",DragDropEffects.Copy);    
    }

    private void pictureBQueen_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      DoDragDrop("blackqueen",DragDropEffects.Copy);
    }

    private void pictureBRook_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      DoDragDrop("blackrook",DragDropEffects.Copy);
    }

    private void pictureBBishop_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      DoDragDrop("blackbishop",DragDropEffects.Copy);    
    }

    private void pictureBKnight_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      DoDragDrop("blackknight",DragDropEffects.Copy);
    }

    private void pictureBPawn_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      DoDragDrop("blackpawn",DragDropEffects.Copy);    
    }
    private void btnNew_Click(object sender, System.EventArgs e)
    {
      ClearLayer(Layers.DrawTop);
      ClearLayer(Layers.DrawMid);
      editPosition.ChessBoardGui.NewPosition();
    }
    private void btnClear_Click(object sender, System.EventArgs e)
    {
      ClearLayer(Layers.DrawTop);
      ClearLayer(Layers.DrawMid);
      editPosition.ChessBoardGui.ClearPosition();
    }

    private void MoveSquare_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      MoveSquare.BackColor =  GetColor(MoveSquare.BackColor);
      editPosition.ChessBoardGui.AttacksColor = MoveSquare.BackColor;
      savePosition.AttacksColor = MoveSquare.BackColor;
      editPosition.Invalidate();

    }

    private void imageHeight_ValueChanged(object sender, System.EventArgs e)
    {
    
    }

    private void FENImages_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
    
    }

    private void FENImages_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
      SaveInformation(coGlobalSettings,"ConfigValues.xml");    
    }

    private void FENImages_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    
    }

    private void FENImages_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
    {
      if(e.Control )
      {
        if( e.KeyCode == Keys.C )
        {
          TransferToSavePosition();
          Clipboard.SetDataObject(savePosition.Drawing,true);
          e.Handled = true;
        }
      }
   
    }

    private void btnClearLayer_Click(object sender, System.EventArgs e)
    {
      ClearLayer((Layers) whatLayer.SelectedItem);
      editPosition.Invalidate();
    }
    void ClearLayer(Layers layer)
    {
      editPosition.ChessBoardGui.ActiveLayer = layer;
      editPosition.ChessBoardGui.ClearLayer();
      savePosition.ActiveLayer = layer;
      savePosition.ClearLayer();
    }

  
    private void btnSideToMove_CheckedChanged(object sender, System.EventArgs e)
    {
      editPosition.ChessBoardGui.Validation.SideToMove = btnSideToMove.Checked;    
    }

    private void FENImages_Load(object sender, System.EventArgs e)
    {
    
    }

    private void btnGetFen_Click(object sender, System.EventArgs e)
    {
      txtFEN.Text = editPosition.ChessBoardGui.ImageFenNotation;
    
    }

    private void btnSetFen_Click(object sender, System.EventArgs e)
    {
      try
      {
        editPosition.ChessBoardGui.FenNotation = txtFEN.Text;
      }
      catch(Exception ex)
      {
        System.Windows.Forms.MessageBox.Show(ex.Message);
      }
    }

    private void menuItem1_Click(object sender, System.EventArgs e)
    {
    }

    private void menuItem4_Click(object sender, System.EventArgs e)
    {
      AboutBox ab = new AboutBox();
      ab.ShowDialog();
      ab.Dispose();    
    }
   
   
	}
}
